import re


def make_search_condition(data: dict, fuzzy_field: list):
    """orm拼接where条件
    """
    # if start_time:
    #    condition += f" and create_time >= '{start_time}'"
    # if end_time:
    #    condition += f" and create_time <= '{end_time}'"
    sql = ""
    for k, v in data.items():
        if not v:
            continue
        elif isinstance(v, int):
            sql += f"{k} = {v} and "
        elif isinstance(v, str):
            if k in fuzzy_field:
                sql += f"{k} like '%%{v}%%' and "
                continue
            sql += f"{k} = '{v}' and "

    sql = sql[:-5] if sql else "1=1"
    return sql


def checkout_email(email):
    rex = r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)"
    # 匹配不上返回None
    return re.match(rex, email)

